#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:6031)


//https://leetcode.cn/problems/product-of-array-except-self/
class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        vector<int> v;
        int n = nums.size();

        vector<int> f(n, 1);
        vector<int> g(n, 1);

        for (int i = 1; i < n; i++)
        {
            f[i] = f[i - 1] * nums[i - 1];
        }
        for (int j = n - 2; j >= 0; j--)
        {
            g[j] = g[j + 1] * nums[j + 1];
        }

        for (int i = 0; i < n; i++)
        {
            v.push_back(f[i] * g[i]);
        }
        return v;
    }
};